<template>
<!--保险公司结算用 投保单列表页 -->
    <div>
        <el-form :inline="true"  class="demo-form-inline">

            <el-form-item label="时间范围(确认时间)" v-if="type!='渠道销售'">
                <el-date-picker v-model="stimeArry" type="daterange" placeholder="选择日期范围">
                </el-date-picker>
            </el-form-item>            
            <el-form-item label="保险分公司" >
                <el-select v-model="company" placeholder="所属分公司">
                    <el-option label="所有" value=""></el-option>
                <el-option label="总公司营业部" value="总公司营业部"></el-option>
                <el-option label="青海分公司" value="青海分公司"></el-option>
                <el-option label="北京分公司" value="北京分公司"></el-option>
                <el-option label="天津分公司" value="天津分公司"></el-option>
                <el-option label="河北分公司" value="河北分公司"></el-option>
                <el-option label="山西分公司" value="山西分公司"></el-option>
                <el-option label="内蒙古分公司" value="内蒙古分公司"></el-option>
                <el-option label="辽宁分公司" value="辽宁分公司"></el-option>
                <el-option label="大连分公司" value="大连分公司"></el-option>
                <el-option label="吉林分公司" value="吉林分公司"></el-option>
                <el-option label="黑龙江分公司" value="黑龙江分公司"></el-option>
                <el-option label="上海分公司" value="上海分公司"></el-option>
                <el-option label="江苏分公司" value="江苏分公司"></el-option>
                <el-option label="浙江分公司" value="浙江分公司"></el-option>
                <el-option label="宁波分公司" value="宁波分公司"></el-option>
                <el-option label="安徽分公司" value="安徽分公司"></el-option>
                <el-option label="福建分公司" value="福建分公司"></el-option>
                <el-option label="厦门分公司" value="厦门分公司"></el-option>
                <el-option label="江西分公司" value="江西分公司"></el-option>
                <el-option label="山东分公司" value="山东分公司"></el-option>
                <el-option label="青岛分公司" value="青岛分公司"></el-option>
                <el-option label="河南分公司" value="河南分公司"></el-option>
                <el-option label="湖北分公司" value="湖北分公司"></el-option>
                <el-option label="湖南分公司" value="湖南分公司"></el-option>
                 <el-option label="广东分公司" value="广东分公司"></el-option>
                <el-option label="广西分公司" value="广西分公司"></el-option>
                <el-option label="重庆分公司" value="重庆分公司"></el-option>
                <el-option label="云南分公司" value="云南分公司"></el-option>
                <el-option label="陕西分公司" value="陕西分公司"></el-option>
                <el-option label="甘肃分公司" value="甘肃分公司"></el-option>
                <el-option label="海南分公司" value="海南分公司"></el-option>
                <el-option label="新疆分公司" value="新疆分公司"></el-option>
                <el-option label="贵州分公司" value="贵州分公司"></el-option>
                <el-option label="宁夏分公司" value="宁夏分公司"></el-option>
                <el-option label="航运保险运营中心" value="航运保险运营中心"></el-option>
               
            </el-select>
            </el-form-item>    
            <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
            </el-form-item>
            <el-form-item  v-if="type=='公司销售服务费'">
             <el-button type="primary" size="media" @click="serverMoney" :disabled="!(tableData3.length>0)">
                        导出服务费
                    </el-button>
            </el-form-item>
            <el-form-item  v-if="type=='公司销售佣金'">
            <el-button type="primary" size="media" @click="Commission" :disabled="!(tableData3.length>0)">
                      导出佣金
                    </el-button>
            </el-form-item>
             <el-form-item  v-if="type=='公司销售有效保单'">
            <el-button type="primary" size="media" @click="vliad" :disabled="!(tableData3.length>0)">
                      导出有效保单
                    </el-button>
            </el-form-item>
            <el-form-item  v-if="type=='渠道销售'">
            <el-button type="primary" size="media" @click="organizationMoney" >
                      导出
                    </el-button>
            </el-form-item>
              <el-form-item  v-if="type!='渠道销售'&& type!='公司销售佣金' && type!='公司销售有效保单' && type!='公司销售服务费'">
            <el-button type="primary" size="media" @click="addList" :disabled="selectList.length==0">
                      添加
                    </el-button>
            </el-form-item>
             <el-form-item  v-if="type!='渠道销售'&& type!='公司销售佣金' && type!='公司销售有效保单' && type!='公司销售服务费'">
            <el-button type="primary" size="media" @click="updateAll"  :disabled="centerList.length==0">
                      全部提交
                    </el-button>
            </el-form-item>
        </el-form>
        <el-table v-if="tableData3.length>0" :data="tableData3" border style="width: 100%"  @selection-change="handleSelectionChange">
 <el-table-column v-if="type!='渠道退保' && type!='公司销售佣金' && type!='公司销售有效保单' && type!='公司销售服务费'"
      type="selection"
      width="55"      
      >
            </el-table-column>
            <el-table-column prop="CUSTOM_NAME" label="被保险人姓名" width="180">
            </el-table-column>           
            <el-table-column prop="Salesdetail.PRODUCE_NAME" label="产品名称" width="180" >
            </el-table-column>
            <el-table-column prop="Companymoney.COMPANYMONEY_TIME" label="确认时间" width="180" :formatter="localDataFomatter">
            </el-table-column>
            <el-table-column prop="Companymoney.COMPANYMONEY_SEVERMONEY" label="服务费" width="200">
            </el-table-column>
            <el-table-column prop="Companymoney.COMPANYMONEY_COMAPNYMONEY" label="结算保险费" width="200">
            </el-table-column>
            <el-table-column prop="Companymoney.COMPANYMONEY_COMMISSIONMONEY" label="佣金" width="200">
            </el-table-column>
            <el-table-column prop="Companymoney.COMPANYMONEY_TYPE" label="备注" width="200">
            </el-table-column>          
               <el-table-column label="操作" width="200" fixed="right" v-if="type=='渠道退保'">
                <template scope="scope">
                    <el-button type="text" size="media" @click="goBackCenter(scope.row)">
                        <i class="el-icon-view"> 确认</i>
                    </el-button>
                </template>
            </el-table-column>
              <el-table-column label="操作" width="200" fixed="right" v-if="type=='公司保费支付确认'|| type=='公司佣金确认'|| type=='公司服务费确认'">
                <template scope="scope">
                    <el-button type="text" size="media" @click="goCenterCompany(scope.row)">
                        <i class="el-icon-view"> 确认</i>
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page="currentPage1" :page-size="10" layout="total, prev, pager, next" :total="pagecount">
            </el-pagination>
        </div>
           
    </div>
</template>
<script>
import api from "@/js/api";
export default {
  data() {
    return {
      stimeArry: [], //销售时间
      btimeArry: [], //退保时间
      mtimeArry: [], //到账时间
      //   searchModel: {
      //     beginTime: "",
      //     endTime: ""
      //   },
      pagecount: 0,
      currentPage1: 1,
      tableData3: [],
      idList: [], //添加到 导出列表，
      selectList: [],
      addBool: false,
      backCenterBool: false,
      centerList: [], //批量确认,
      company: ""
    };
  },
  props: {
    id: {
      type: {
        type: String,
        default: ""
      }
    },
    type: {
      type: String,
      default: "公司"
    }
  },
  computed: {
    widthGet() {
      if (this.type == "公司") {
        return 280;
      } else {
        return 200;
      }
    }
  },
  methods: {
    //时间过滤器
    localDataFomatter(row, column, cellValue) {
      if(!cellValue){
        return;
      }
        cellValue = cellValue + "Z";
      var data = new Date(cellValue);
      var dataString =
        data.getFullYear() +
        "/" +
      ((data.getMonth()+1)>=10?(data.getMonth() + 1):"0"+(data.getMonth() + 1))+
        "/" +
        (data.getDate()>=10?data.getDate():"0"+data.getDate());
        // " " +
        // (data.getHours()>=10?data.getHours():"0"+data.getHours())+
        // ":" +
        // (data.getMinutes()>=10?data.getMinutes():"0"+data.getMinutes());
      return dataString;
    },
    changeInformation(id) {
      this.$emit("changeInformation", id);
    },
    //确认
    goCenterCompany(obj) {
      var date = [
        {
          Id: obj.Companymoney.COMPANYMONEY_ID,
          Type: this.type
        }
      ];
      let that = this;
      api.PutCenter(this, date, function(msg) {
        that.getDate();
        that.$notify.success({
          title: "成功",
          message: "提交成功"
        });
      });
    },
    updateAll() {
      let that = this;
      api.PutCenter(this, this.centerList, function(msg) {
        that.getDate();
        that.$notify.success({
          title: "成功",
          message: "提交成功"
        });
      });
    },
    //添加id
    addList() {
      for (var i = 0; i < this.selectList.length; i++) {
        var obj = {
          Id: this.selectList[i].Companymoney.COMPANYMONEY_ID,
          Type: this.type
        };
        this.centerList.push(obj);
      }
      this.addBool = false;
    },
    //多选回调
    handleSelectionChange(val) {
      this.selectList = val;
      this.addBool = true;
    },
    //分页
    handleCurrentChange(vule) {
      // console.log(vule);
      this.currentPage1 = vule;
      this.getDate();
    },
    onSubmit() {
      this.getDate();
    },

    ///下载渠道佣金
    organizationMoney() {
      //
      var obj = {
        type: "需结算",
        timeStart: "",
        timeEnd: "",
        idList: "",
        company: ""
      };
      if (this.type == "渠道销售") {
        obj.type = "需结算";
      } else {
        obj.type = "已退保";
      }
      if (this.mtimeArry.length > 0) {
        obj.timeStart = new Date(this.mtimeArry[0]).toLocaleDateString();
        obj.timeEnd = new Date(this.mtimeArry[1]).toLocaleDateString();
      }
      if (this.idList.length > 0) {
        obj.idList = this.idList;
      }
      let that = this;
      api.PutOrganizationMoney(that, obj, function(msg) {
        // console.log(msg.Result.FilesList);
        var trueUrl = api.download(msg.Result.FilesList[0]);
        window.open(trueUrl);
      });
    },
    //下载服务费 excel
    serverMoney() {
      var data = {
        TimeStart: "",
        TimeEnd: "",
        company: this.company
      };
      if (this.stimeArry.length != 0) {
        data.TimeStart = new Date(this.stimeArry[0]).toLocaleDateString();
        data.TimeEnd = new Date(this.stimeArry[1]).toLocaleDateString();
      }
      api.GetServerMoney(this, data, function(msg) {
        // console.log(msg.Result.FilesList);
        var trueUrl = api.download(msg.Result.FilesList[0]);
        window.open(trueUrl);
      });
    },
    //下载保险公司佣金
    Commission() {
      var data = {
        TimeStart: "",
        TimeEnd: "",
        company: this.company
      };
      if (this.stimeArry.length != 0) {
        data.TimeStart = new Date(this.stimeArry[0]).toLocaleDateString();
        data.TimeEnd = new Date(this.stimeArry[1]).toLocaleDateString();
      }
      api.GetCommission(this, data, function(msg) {
        // console.log(msg.Result.FilesList);
        var trueUrl = api.download(msg.Result.FilesList[0]);
        window.open(trueUrl);
      });
    },
    //下载有效保单
    vliad() {
      var data = {
        TimeStart: "",
        TimeEnd: "",
        company: this.company
      };
      if (this.stimeArry.length != 0) {
        data.TimeStart = new Date(this.stimeArry[0]).toLocaleDateString();
        data.TimeEnd = new Date(this.stimeArry[1]).toLocaleDateString();
      }
      api.Getvliad(this, data, function(msg) {
        // console.log(msg.Result.FilesList);
        var trueUrl = api.download(msg.Result.FilesList[0]);
        window.open(trueUrl);
      });
    },
    getDateGet(type) {
      let that = this;
      var obj = {
        pageSize: 10,
        pageIndex: this.currentPage1,
        Type: type,
        StimeStart: "",
        StimeEnd: "",
        TtimeStart: "",
        TtimeEnd: "",
        company: this.company
      };
      //销售时间
      if (this.stimeArry.length > 0 && this.stimeArry[0]) {
        obj.StimeStart = new Date(this.stimeArry[0]).toLocaleDateString();
        obj.StimeEnd = new Date(this.stimeArry[1]).toLocaleDateString();
      }
      if (this.btimeArry.length > 0 && this.btimeArry[0]) {
        obj.TtimeStart = new Date(this.btimeArry[0]).toLocaleDateString();
        obj.TtimeEnd = new Date(this.btimeArry[1]).toLocaleDateString();
      }
      // obj.Type = "导出";
      api.GetCOMPANYMONEYList(this, obj, function(msg) {
        that.tableData3 = msg.Result;
        that.pagecount = msg.ListCount;
      });
    },
    //获取数据
    getDate() {
      let that = this;
      var data = {
        pageIndex: this.currentPage1,
        pageSize: 10,
        stateTime: "",
        endTime: "",
        type: this.type,
        company: this.company
      };
      //销售时间
      if (this.stimeArry.length > 0 && this.stimeArry[0]) {
        data.stateTime = new Date(this.stimeArry[0]).toLocaleDateString();
        data.endTime = new Date(this.stimeArry[1]).toLocaleDateString();
      }
      //
      api.GetCOMPANYMONEYList(that, data, function(msg) {
        that.tableData3 = msg.Result;
        that.pagecount = msg.ListCount;
      });
    }
  },
  activated() {
    // console.log(this.type);
    this.getDate();
  }
};
</script>

